package com.yzw.teacher.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzw.common.domain.EduTeacher;
import com.yzw.common.mapper.EduTeacherMapper;
import com.yzw.common.vo.SearchTeacherVo;
import com.yzw.teacher.service.EduTeacherService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 *
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher>
        implements EduTeacherService {

    @Override
    public Page<EduTeacher> getPage(Integer pageNum,Integer pageSize, SearchTeacherVo searchTeacherVo) {
        Page<EduTeacher> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<EduTeacher> queryWrapper = new LambdaQueryWrapper();
        if (!ObjectUtils.isEmpty(searchTeacherVo.getName())) {
            queryWrapper.like(EduTeacher::getName, searchTeacherVo.getName());
        }
        if (!ObjectUtils.isEmpty(searchTeacherVo.getLevel())) {
            queryWrapper.eq(EduTeacher::getLevel, searchTeacherVo.getLevel());
        }
        if (!ObjectUtils.isEmpty(searchTeacherVo.getDateList())) {
            queryWrapper.between(EduTeacher::getEduCreate, searchTeacherVo.getDateList().get(0),
                    searchTeacherVo.getDateList().get(1));
        }
        queryWrapper.eq(EduTeacher::getIsDeleted, 0);
        queryWrapper.orderByAsc(EduTeacher::getSort);
        Page<EduTeacher> p = baseMapper.selectPage(page, queryWrapper);
        return p;
    }

    @Override
    public void delete(Long id) {
        LambdaUpdateWrapper<EduTeacher> updateWrapper = new UpdateWrapper<EduTeacher>().lambda();
        updateWrapper.set(EduTeacher::getIsDeleted, 1).eq(EduTeacher::getId, id);
        baseMapper.update(new EduTeacher(), updateWrapper);
    }
}
